package com.wyt.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wyt.dao.TbookMapper;
import com.wyt.dao.TdepartmentMapper;
import com.wyt.dao.TemployeeMapperDao;
import com.wyt.dao.TinstorageDetailMapper;
import com.wyt.entity.Tbook;
import com.wyt.entity.Tdepartment;
import com.wyt.entity.Temployee;
import com.wyt.entity.TinstorageDetail;
import com.wyt.until.TableLayui;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.InetAddress;
import java.util.*;
@Controller
public class sdsfss {

    @Autowired
    private TdepartmentMapper tdepartmentMapper;


    @Autowired
    private TemployeeMapperDao temployeeMapperDao;

    @RequestMapping("/templyee/querySEmpCount")
    @ResponseBody
    private TableLayui querySEmpCount(Integer page, Integer limit){
        PageHelper.startPage(page,limit);
        List<Temployee> list=temployeeMapperDao.selectAllByEAddressAndEStatusAndEStatus();
        PageInfo pageInfo=new PageInfo(list);
        return new TableLayui(0,"",pageInfo.getTotal(),pageInfo.getList());
    }

    @RequestMapping("/templyee/querySEmpCounttwo")
    @ResponseBody
    private List<Temployee> querySEmpCount2(){
        List<Temployee> list=temployeeMapperDao.selectAllByEAddressAndEStatusAndEStatus();
        return list;
    }

    //公司在职员工
    @RequestMapping("querySEmpCountYuan")
    @ResponseBody
    public List<Tdepartment> querySEmpCount() {
        return tdepartmentMapper.findAllDept3();
    }

    //查询本机名称和ip地址
    @RequestMapping("/Os/detail")
    @ResponseBody
    private Map<String, Object> getIpAndOs() {
        Map map = new HashMap();
        try {
            InetAddress addr = InetAddress.getLocalHost();
            String ip = addr.getHostAddress().toString(); //获取本机ip
            String hostName = addr.getHostName().toString(); //获取本机计算机名称
            System.out.println("本机IP：" + ip + "\n本机名称:" + hostName);
            Properties props = System.getProperties();
            System.out.println("操作系统的名称：" + props.getProperty("os.name"));
            System.out.println("操作系统的版本号：" + props.getProperty("os.version"));
            map.put("ip",ip);
            map.put("osname", props.getProperty("os.name"));
            return map;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Autowired
    private TinstorageDetailMapper tinstorageDetailMapper;

    @RequestMapping("/bookCharts/BookSumCount")
    @ResponseBody
    private Map<String,Object> selectAllBookNameCountTotal(Integer value){
        List<TinstorageDetail> list= tinstorageDetailMapper.selectAllByBooknameBySumCount(value);
        Map<String,Object> map=new HashMap<>();
        List list1=new ArrayList();
        List list2=new ArrayList();
        for (TinstorageDetail t:list
        ) {
            list1.add(t.getBookname());
            list2.add(t.getBookCountTotal());
        }
        map.put("value",list2);
        map.put("name",list1);
        return map;
    }
    @Autowired
    private TbookMapper tbookMapper;

    @RequestMapping("/bookChart/BookSumCountonr")
    @ResponseBody
    Map<String,Object> selectAllBookcountAndBookcount(){
        List<Tbook> list= tbookMapper.selectAllBookcountAndBookcount();
        Integer value1=0,value2=0;
        for (Tbook t:list){
            if (t.getBookstate().equals(1)){
                value1 += t.getBookcount();
            }else {
                value2 += t.getBookcount();
            }
        }
        Map<String,Object> map=new HashMap<>();
        map.put("value1",value1);
        map.put("value2",value2);
        map.put("value3",value1+value2);

        return map;
    }


}
